//==================================================================
/// CppKazRace_Anim.cpp
///
/// Created by Davide Pasca - 2010/4/1
/// See the file "license.txt" that comes with this project for
/// copyright info. 
//==================================================================

#include "stdafx.h"
#include "CppKazRace.h"

//==================================================================
void CppKazRace::anim_cars()
{
	for (size_t i=0; i < mpoVehicles.size(); ++i)
	{
		mpoVehicles[i]->animate( mpoRoad->far_pos_get() );
	}
}

//==================================================================
void CppKazRace::animate()
{
	/*
	mpoPO->add( DUT::SSPrintFS( "Speed = %i", mPlayerCar.mSpeed ) );
	mpoPO->add( DUT::SSPrintFS( "Accel = %i", mPlayerCar.mAccel ) );
	mpoPO->add( DUT::SSPrintFS( "_wheel_pos = %i", mPlayerCar._wheel_pos ) );
	mpoPO->add( DUT::SSPrintFS( "roadXAccel = %i", roadXAccel ) );
	mpoPO->add( DUT::SSPrintFS( "carXAccel = %i", carXAccel ) );
	*/

	PlayerCar::AnimParams	playerAnimPar;

	playerAnimPar.mLeftIsDown	=	mLeftIsDown;
	playerAnimPar.mRightIsDown	=	mRightIsDown;
	playerAnimPar.mUpIsDown		=	mUpIsDown;
	playerAnimPar.mDownIsDown	=	mDownIsDown;
	playerAnimPar.mCurXAcc		=	mpoRoad->_cur_xacc;
	playerAnimPar.mpCollVehicle	=	mpoRoad->collided_vehicle();

	playerAnimPar.mCollVehicleStrength	=
						mpoRoad->collided_vehicle_strength();

	playerAnimPar.mEdgeCollisionVal		=
						mpoRoad->edge_collision( mpoMyCarSptr->mX, mpoMyCarSptr->mY, mpoMyCarSptr->mZ ); // -102400

	float	carXAccel;
	float	roadXAccel;
	// animate the player's car accordingly
	mPlayerCar.Animate( playerAnimPar, carXAccel, roadXAccel );

	// apply the resultant car and road horizontal acceleration
	// to the horizon and the road
	mpoHor->x_set( mpoHor->_x - roadXAccel/10000.0f );
	mpoRoad->x_off( roadXAccel + carXAccel );

	// offset the road in place, depending on how deep into the edge we are
	if ( playerAnimPar.mEdgeCollisionVal )
	{
		mpoRoad->x_off( playerAnimPar.mEdgeCollisionVal );	// -128*100
	}

	// advance the road
	mpoRoad->pos_set( mpoRoad->pos_get() + mPlayerCar.mSpeed );	// 46 = ~50km/h

	// render particles
	{
		float	y = mpoMyCarSptr->mY + 15;
		float	z = mpoMyCarSptr->mZ + mScreenD - 700;
		float	vz = -mPlayerCar.mSpeed / 8;

		mpoSmokeLPart->idle( mpoMyCarSptr->mX-45, y, z, 0, 0, vz );
		mpoSmokeRPart->idle( mpoMyCarSptr->mX+45, y, z, 0, 0, vz );
	}

	anim_cars();
}
